import 'dart:convert';

import 'package:flutter_bilibili/http/request/base_request.dart';

/// 网络请求抽象类
abstract class HiNetAdaptor {
  Future<HiNetResponse> send<T>(BaseRequest request);
}

/// 统一网络层返回格式
class HiNetResponse<T> {
  T data;
  BaseRequest request;
  int statusCode;
  String statusMessage;
  dynamic extra;

  HiNetResponse({
    required this.data,
    required this.statusCode,
    required this.request,
    required this.statusMessage,
  });

  @override
  String toString() {
    if (data is Map) {
      return jsonEncode(data);
    }
    return data.toString();
  }
}
